/*
 * Copyright (c) 2013-2015 Charkey. All rights reserved.
 *
 * This software is the confidential and proprietary information of Charkey.
 * You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the agreements you entered into with Charkey.
 *
 * Charkey MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
 *
 * Charkey SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING,
 * MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 */

package cn.simastudio.talos.core.service.base;

/**
 * <p>User: Zhang Kaitao
 * <p>Date: 14-2-17
 * <p>Version: 1.0
 */
public interface OAuthService {

    /**
     * 添加 auth_code 到 auth_code_cache
     *
     * @param authCode   授权码auth_code
     * @param credential 用户名
     */
    void addAuthCode(String authCode, String credential);

    /**
     * 添加 access_token
     *
     * @param accessToken access_token
     * @param credential  用户名
     */
    void addAccessToken(String accessToken, String credential);

    /**
     * 添加 refresh_token
     *
     * @param refreshToken             refresh_token
     * @param credentialAndAccessToken 字符串数组，包括 credential 和 accessToken
     */
    void addRefreshToken(String refreshToken, String[] credentialAndAccessToken);

    /**
     * 验证auth_code是否有效：通过auth_code在auth_code_cache查找cache，cache不为空则auth_code有效
     *
     * @param authCode 授权码auth_code
     * @return true：授权码auth_code有效<br/>false：授权码auth_code无效
     */
    boolean checkAuthCode(String authCode);

    /**
     * 校验 access_token 是否已失效
     *
     * @param accessToken access_token
     * @return true：access_token已失效<br/>false：access_token未失效
     */
    boolean checkAccessTokenExpired(String accessToken);

    /**
     * 校验 refresh_token
     *
     * @param refreshToken refresh_token
     * @return true：refresh_token有效<br/>false：refresh_token无效
     */
    boolean checkRefreshToken(String refreshToken);

    /**
     * 校验 client_id
     *
     * @param clientId 客户端id
     * @return true：client_id有效<br/>false：client_id无效
     */
    boolean checkClientId(String clientId);

    /**
     * 校验 client_secret
     *
     * @param clientSecret 客户端secret
     * @return true：client_secret有效<br/>false：client_secret无效
     */
    boolean checkClientSecret(String clientSecret);

    /**
     * 通过 auth_code 获取 credential
     *
     * @param authCode 授权码auth_code
     * @return credential
     */
    String getCredentialByAuthCode(String authCode);

    /**
     * 通过 access_token 获得 credential
     *
     * @param accessToken access_token
     * @return credential
     */
    String getCredentialByAccessToken(String accessToken);

    /**
     * 通过 refresh_token 获取 credential
     *
     * @param refreshToken refresh_token
     * @return credential
     */
    String getCredentialByRefreshToken(String refreshToken);

    /**
     * 通过 refresh_token 获取 access_token
     *
     * @param refreshToken refresh_token
     * @return access_token
     */
    String getAccessTokenByRefreshToken(String refreshToken);

    /**
     * auth_code 过期时间
     *
     * @return auth_code 过期时间
     */
    long getAuthCodeExpireIn();

    /**
     * access_token 过期时间
     *
     * @return 过期时间
     */
    long getAccessTokenExpireIn();

    /**
     * 失效 auth_code
     *
     * @param authCode 授权码auth_code
     */
    void evictAuthCode(String authCode);

    /**
     * 失效 refresh_token
     *
     * @param refreshToken refresh_token
     */
    void evictRefreshToken(String refreshToken);

}
